package br.com.ustore.agent.backup.runner;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import br.com.ustore.agent.backup.producer.AgentBackupService;

public class TestJmsBackupData implements Observer {
	
	public static void main(String[] args) {

		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"app-client.xml");
		AgentBackupService agentBackupService = (AgentBackupService) ctx
				.getBean("agentBackupService");

		// ler o log
		BufferedReader info = null;
		try {
			info = new BufferedReader(
					new FileReader(
							"D:/Cesar/eclipse/workspace-jamaica/p2p_client/rateBackupLogger.log"));
			
			while (info.ready()) {
				String line = info.readLine();
				
				if (line.contains("INFO")){
					String [] data = line.split(" ");
					agentBackupService.sendData(Long.parseLong(data[2]), Long.parseLong(data[4]), Long.parseLong(data[6]), Integer.parseInt(data[8]), Integer.parseInt(data[10]));
				}
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			try {
				info.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public void update(Observable arg0, Object arg1) {
	}
	
	/*
	SimplePeerController simplePeerController;

	public TestJmsBackupData() {
		super();
		simplePeerController = new SimplePeerController();
		simplePeerController.addObserver(this); // adiciona essa classe como um observador dos dados
	}

	public void update(Observable arg0, Object arg) {
		SwingUtilities.invokeLater(new Runnable() {

			public void run() {

				System.out.println("<----------TESTE-------------->");
			}
		});
	}
	*/
}
